/*
 * vga.h
 *
 *  Created on: 2021年3月21日
 *      Author: root
 */

#ifndef INCLUDE_DRIVERS_VGA_H_
#define INCLUDE_DRIVERS_VGA_H_

#include <common/types.h>
#include <hardwarecommunication/port.h>
#include <drivers/driver.h>


namespace myos{
	namespace drivers{

	class VideoGraphicsArray{
	protected:
		hardwarecommunication::Port8Bit miscPort;
		hardwarecommunication::Port8Bit crtcIndexPort;	//控制器索引
		hardwarecommunication::Port8Bit crtcDataPort;	//控制器数据方式
		hardwarecommunication::Port8Bit sequencerIndexPort;
		hardwarecommunication::Port8Bit sequencerDataPort;
		hardwarecommunication::Port8Bit graphicsControllerIndexPort;
		hardwarecommunication::Port8Bit graphicsControllerDataPort;
		hardwarecommunication::Port8Bit attributeControllerIndexPort;
		hardwarecommunication::Port8Bit attributeControllerReadPort;
		hardwarecommunication::Port8Bit attributeControllerWritrPort;
		hardwarecommunication::Port8Bit attributeControllerResetPort;

		void  WriteRegisters(myos::common::uint8_t * registers);
		myos::common::uint8_t* GetFrameBufferSegment();


		virtual  myos::common::uint8_t GetColorIndex(myos::common::uint8_t r,myos::common::uint8_t g,myos::common::uint8_t b);


	public:
		VideoGraphicsArray();
		~VideoGraphicsArray();

		virtual bool SupportsMode(myos::common::uint32_t width,myos::common::uint32_t height,myos::common::uint32_t colordepth);
		virtual bool SetMode(myos::common::uint32_t width,myos::common::uint32_t height,myos::common::uint32_t colordepth);

		virtual void PutPixel(myos::common::int32_t x,myos::common::int32_t y,myos::common::uint8_t r,myos::common::uint8_t g,myos::common::uint8_t b);
		virtual void PutPixel(myos::common::int32_t x,myos::common::int32_t y,myos::common::uint8_t colorIndex);

		virtual void FillRectangle(myos::common::uint32_t x,myos::common::uint32_t y,myos::common::uint32_t w,myos::common::uint32_t h,myos::common::uint8_t r,myos::common::uint8_t g,myos::common::uint8_t b);


	};


	}
}



#endif /* INCLUDE_DRIVERS_VGA_H_ */
